#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""This is the entry of the PiggyMail webmail system.
"""

__author__ = 'Yong Liu'
__version__ = '0.1'
__date__ = '2010-07-06'

import sys, os
abspath = os.path.dirname(__file__)
sys.path.append(abspath)
os.chdir(abspath)

import web

import config
import app.controllers
from app.models import imap
from app.helpers import custom_error
from config import host, protocol, port

urls = (
    '/', 'app.controllers.user.login',
    '/select_lang', 'app.controllers.user.select_lang',
    '/index', 'app.controllers.mail.welcome'
    )

app = web.application(urls,globals())

#Use session
session = web.session.Session(app, web.session.DiskStore('/tmp/sessions'))
m = imap.imap4(host, protocol, port)

def session_hook():
    web.ctx.session = session
    web.ctx.server = m

app.add_processor(web.loadhook(session_hook))

#Control error
custom_error.add(app)

#if __name__ == "__main__":
#    app.run()

application = app.wsgifunc()
